<!--
  Expects the following variables:
  podTemplateContainer
  imagesByDockerReference (optional)
  builds (optional)
  detailed (optional)
  labelPrefix (optional)
 -->

<div class="pod-template">
  <div class="component-label"><span ng-bind-template="{{labelPrefix||'Container'}}:"></span> {{container.name}}</div>

  <div row ng-if="container.image" class="pod-template-image icon-row">
    <div class="icon-wrap">
      <span class="pficon pficon-image" aria-hidden="true"></span>
    </div>
    <div flex class="word-break">
      <span class="pod-template-key">Image:</span>
      <span ng-if="!imagesByDockerReference[container.image]">{{container.image | imageStreamName}}</span>
      <span ng-if="imagesByDockerReference[container.image]">
            <a ng-href="{{imagesByDockerReference[container.image].imageStreamName | navigateResourceURL : 'ImageStream' : imagesByDockerReference[container.image].imageStreamNamespace}}">{{container.image | imageStreamName}}</a>
            <span class="hash" title="{{imagesByDockerReference[container.image].metadata.name}}">{{imagesByDockerReference[container.image].metadata.name | stripSHAPrefix | limitTo: 7}}</span>
            <span ng-if="imagesByDockerReference[container.image].dockerImageMetadata.Size" class="small text-muted nowrap">
              {{imagesByDockerReference[container.image].dockerImageMetadata.Size | humanizeSize}}
            </span>
          </span>
    </div>
  </div>

  <div ng-if="imagesByDockerReference && container.image && (image = imagesByDockerReference[container.image])" class="pod-template-build">
    <div row class="icon-row" ng-if="build = (image | buildForImage : builds)">
      <div class="icon-wrap">
        <span class="fa fa-refresh" aria-hidden="true"></span>
      </div>
      <div flex class="word-break">
        <span class="pod-template-key">Build:</span>
        <span ng-if="build | configURLForResource">
              <a ng-href="{{build | configURLForResource}}">{{build | buildConfigForBuild}}</a>,
            </span>
        <a ng-href="{{build | navigateResourceURL}}">
          <span ng-if="(build | annotation : 'buildNumber')">#{{build | annotation : 'buildNumber'}}</span>
          <span ng-if="!(build | annotation : 'buildNumber')">{{build.metadata.name}}</span>
        </a>
      </div>
    </div>
    <div row class="icon-row" ng-if="build.spec.source">
      <div class="icon-wrap">
        <span class="fa fa-code" aria-hidden="true"></span>
      </div>
      <div flex class="word-break">
        <span class="pod-template-key">Source:</span>
        <span ng-switch="build.spec.source.type">
              <span ng-switch-when="Git">
                <span ng-if="build.spec.revision.git.commit">
                  {{build.spec.revision.git.message}}
                  <osc-git-link
                    class="hash"
                    uri="build.spec.source.git.uri"
                    ref="build.spec.revision.git.commit">{{build.spec.revision.git.commit | limitTo:7}}</osc-git-link>
                  <span ng-if="detailed && build.spec.revision.git.author">
                    authored by {{build.spec.revision.git.author.name}}
                  </span>
                </span>
                <span ng-if="!build.spec.revision.git.commit">
                  <osc-git-link uri="build.spec.source.git.uri">{{build.spec.source.git.uri}}</osc-git-link>
                </span>
              </span>
              <span ng-switch-default>
                {{build.spec.source.type || 'Unknown'}}
              </span>
            </span>
      </div>
    </div>
  </div>

  <div row ng-if="detailed && (container.command.length || container.args.length)" class="icon-row">
    <div class="icon-wrap">
      <span aria-hidden="true" class="fa fa-terminal"></span>
    </div>
    <div flex class="word-break">
          <span class="pod-template-key">
            Command:
          </span>
      <span>
            <code class="command">
              <truncate-long-text
                content="container | entrypoint : imagesByDockerReference[container.image]"
                limit="80"
                newline-limit="1"
                expandable="true"
                use-word-boundary="false">
              </truncate-long-text>
            </code>
          </span>
    </div>
  </div>

  <div row ng-if="container.ports.length > 0" class="pod-template-ports icon-row">
    <div class="icon-wrap">
      <span aria-hidden="true" class="pficon pficon-port"></span>
    </div>
    <div flex class="word-break">
      <span class="pod-template-key">Ports:</span>
      <span ng-repeat="port in container.ports | orderBy: 'containerPort' | limitToOrAll : detailed ? undefined : 1">
        <span class="nowrap">{{port.containerPort}}/{{port.protocol}}</span><span ng-if="port.name"><span class="nowrap"> ({{port.name}})</span></span><span ng-if="port.hostPort"><span class="nowrap"><span class="port-icon"> &#8594;</span> {{port.hostPort}}</span></span><span ng-if="!$last">, </span>
      </span>
      <span ng-if="!detailed && container.ports.length >= 2">
        and {{container.ports.length - 1}}
        <span ng-if="container.ports.length > 2">others</span>
        <span ng-if="container.ports.length === 2">other</span>
      </span>
    </div>
  </div>

  <div row ng-if="detailed" ng-repeat="mount in container.volumeMounts" class="icon-row">
    <div class="icon-wrap">
      <span aria-hidden="true" class="fa fa-database"></span>
    </div>
    <div flex class="word-break">
      <span class="pod-template-key">Mount:</span>
      <span>
            {{mount.name}}<span ng-if="mount.subPath">, subpath {{mount.subPath}}</span>&#8201;&#8594;&#8201;<span>{{mount.mountPath}}</span>
            <small class="text-muted">{{mount | volumeMountMode : podTemplate.spec.volumes}}</small>
          </span>
    </div>
  </div>

  <div row ng-if="detailed && (container.resources.requests.cpu || container.resources.limits.cpu)" class="icon-row">
    <div class="icon-wrap">
      <i class="fa fa-area-chart" aria-hidden="true"></i>
    </div>
    <div flex>
      <span class="pod-template-key">CPU:</span>
      <span ng-if="container.resources.requests.cpu && container.resources.limits.cpu">
            {{container.resources.requests.cpu | usageWithUnits: 'cpu'}} to {{container.resources.limits.cpu | usageWithUnits: 'cpu'}}
          </span>
      <span ng-if="!container.resources.requests.cpu">
            {{container.resources.limits.cpu | usageWithUnits: 'cpu'}} limit
          </span>
      <span ng-if="!container.resources.limits.cpu">
            {{container.resources.requests.cpu | usageWithUnits: 'cpu'}} requested
          </span>
    </div>
  </div>

  <div row ng-if="detailed && (container.resources.requests.memory || container.resources.limits.memory)" class="icon-row">
    <div class="icon-wrap">
      <i class="fa fa-area-chart" aria-hidden="true"></i>
    </div>
    <div flex>
      <span class="pod-template-key">Memory:</span>
      <span ng-if="container.resources.requests.memory && container.resources.limits.memory">
            {{container.resources.requests.memory | usageWithUnits: 'memory'}} to {{container.resources.limits.memory | usageWithUnits: 'memory'}}
          </span>
      <span ng-if="!container.resources.requests.memory">
            {{container.resources.limits.memory | usageWithUnits: 'memory'}} limit
          </span>
      <span ng-if="!container.resources.limits.memory">
            {{container.resources.requests.memory | usageWithUnits: 'memory'}} requested
          </span>
    </div>
  </div>

  <div row ng-if="detailed && container.readinessProbe" class="icon-row">
    <div class="icon-wrap">
      <i class="fa fa-medkit" aria-hidden="true"></i>
    </div>
    <div flex>
      <span class="pod-template-key">Readiness Probe:</span>
      <probe probe="container.readinessProbe"></probe>
    </div>
  </div>

  <div row ng-if="detailed && container.livenessProbe" class="icon-row">
    <div class="icon-wrap">
      <i class="fa fa-medkit" aria-hidden="true"></i>
    </div>
    <div flex>
      <span class="pod-template-key">Liveness Probe:</span>
      <probe probe="container.livenessProbe"></probe>
    </div>
  </div>

</div>
